<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/index.css">
    <title>嵌套路由</title>
</head>

<body>
    <div id="app">
        <div class="box">
            <router-link to="/suggest" tag="span">推荐</router-link>
            <router-link to="/local" tag="span">本地</router-link>
            
        </div>
        <!-- 定义容器 -->
        <router-view></router-view>

    </div>
    <!-- 定义推荐模板组件 -->
    <template id="suggest">
        <div class="nav">
            <h3>推荐组件，需登录</h3>
            <router-link to="/suggest/login">登录</router-link>
            <router-link to="/suggest/resign">注册</router-link>
            <!-- 定义容器 -->
            <router-view></router-view>
        </div>
    </template>
</body>
<script src='../js/vue.js '></script>
<script src="./js/vue-router.js"></script>
<script>
    let suggest = {
        template: '#suggest'
    }
    let local = {
        template: '<h1>本地组件</h1>'
    }
    let login = {
        template: '<h1>登录组件</h1>'
    }
    let resign = {
        template: '<h1>注册组件</h1>'
    }
    let router = new VueRouter({
        routes: [
            {
                path: "/",
                redirect: "/suggest"
            },
            {
                path: "/suggest",
                component: suggest,
                children: [
                    {
                        path: "login",
                        component: login,
                    },
                    {
                        path: "resign",
                        component: resign
                    }
                ]
            },
            {
                path: "/local",
                component: local
            },

        ]
    })
    let vm = new Vue({
        el: '#app',
        data: {
            msg: 'hello vue.js'
        },
        methods: {},
        router,
    })
</script>

</html>